<?php

namespace app\console\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Cache;
use think\facade\Event;
use Throwable;

/**
 * 刷新房间状态
 * Class RefreshStatus
 * @package app\console\command
 */
class RefreshStatus extends Command
{
    /**
     * 配置指令
     * @return void
     */
    protected function configure()
    {
        // 指令配置
        $this->setName('tetr:refresh')
            ->setDescription('Refresh Process for once.');
    }

    /**
     * 执行指令
     * @param Input $input
     * @param Output $output
     * @return void
     */
    protected function execute(Input $input, Output $output)
    {
        Cache::tag('tetrGame')->clear();
        while (true) {
            try {
                Event::trigger('RefreshLiveStatus', []);
                Event::trigger('RefreshGamePlayStatus', []);
                Event::trigger('RefreshGameRoomInfo', []);
            } catch (Throwable $e) {
                echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
            }
            sleep(1);
        }
    }
}
